package com.qding.park.manager.rest.controller.wx;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qding.park.common.core.exceptions.BaseException;
import com.qding.park.common.core.exceptions.ExceptionMessage;
import com.qding.park.common.core.exceptions.business.validator.RchlValidatorException;
import com.qding.park.common.core.exceptions.system.SystemUnKnown;
import com.qding.park.common.core.validate.RchlValidateBean;
import com.qding.park.common.core.validate.RchlValidateTools;
import com.qding.park.manager.common.rest.domain.AnswerMsg;
import com.qding.park.manager.common.rest.domain.AnswerMsgFactoryImpl;
import com.qding.park.manager.common.rest.enums.ResponseCodeEnum;
import com.qding.park.manager.facade.core.service.common.PayCommonFacade;
import com.qding.park.manager.rest.controller.WebBaseController;

/**
  * @ClassName: WX_Pay_Controller
  * @Description: 微信缴费
  * @author Comsys-Administrator
  * @date 2016年10月17日 下午4:16:34
  */
@RestController
public class WX_Pay_Controller extends WebBaseController{
	
	private static final Log _log = LogFactory.getLog(WX_Pay_Controller.class);
	
	/**
	  * @Fields payFeeFacade : TODO（缴费有关的业务）
	  */
//	@Autowired
//	private PayFeeStatisFacade payFeeStatisFacade;
	
//	@Autowired
//	private PayFeeFacade   payFeeFacade;
	
	@Autowired
	private PayCommonFacade payCommonFacade;
	
	/**
	  * parkingFaresInfo(临停车计费接口)
	  *
	  * @Title: parkingFaresInfo
	  * @Description: TODO
	  * @param @param userId
	  * @param @param phone
	  * @param @param carNum
	  * @param @return    设定文件
	  * @return AnswerMsg    返回类型
	  * @throws
	  */
	@RequestMapping("/wx/payFee/parkingFaresInfo")
	public AnswerMsg parkingFaresInfo(String userId, String phone,String carNum) {
			
		try {
			/******验证字段********/
			RchlValidateBean vb = new RchlValidateBean();
			vb.getPhoneValidate().put("phone", phone);
			vb.getRequiredValidate().put("userId", userId);
			vb.getRequiredValidate().put("carNum", carNum);
			vb.getRequiredValidate().put("phone", phone);
			RchlValidateTools.validate(vb);
			/**************/
			
//			ParkDataResult parkDataResult = payCommonFacade.parkingFaresInfo_rest_wx(Long.valueOf(phone),userId,carNum);
//			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createAnswerMsg(parkDataResult.getData());
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createAnswerMsg(null);
			return answerMsg;
		}catch(RchlValidatorException e){
//			e.getExceptionMessage().appendDetailText("CarController.myCars:"+"userId="+userId+",phone"+phone);
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.VALIDATION_ERROR.getValue(),
					e.getExceptionMessage().getSimpleText()+";"+e.getExceptionMessage().getDetailText());
			return answerMsg;
		}catch(BaseException e){
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.BUSINESS_ERROR.getValue(),
					e.getExceptionMessage().getSimpleText());
			return answerMsg;
		}catch (Exception e) {
			SystemUnKnown ex=new SystemUnKnown(e,
					ExceptionMessage.createExceptionMessage(SystemUnKnown.default_Name,
														"未知Exception", "userId="+userId+",phone="+phone));
			exceptionHandle.handle(ex);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.SYSTEM_ERROR);
			return answerMsg;
		}
	}
	
	/**
	  * createPayment(创建订单)
	  * @Title: createPayment
	  * @Description: TODO
	  * @param @param orderId
	  * @param @return    设定文件
	  * @return AnswerMsg    返回类型
	  * @throws
	  */
	@RequestMapping("/wx/payFee/createPayment")
	public AnswerMsg createPayment(String orderId) {
			
		try {
			/******验证字段********/
			RchlValidateBean vb = new RchlValidateBean();
			vb.getRequiredValidate().put("orderId", orderId);
			RchlValidateTools.validate(vb);
			/**************/
			
//			ParkDataResult parkDataResult = payFeeFacade.createTempPayment_rest_wx(orderId);
//			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createAnswerMsg(parkDataResult.getData());
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createAnswerMsg(null);
			return answerMsg;
		}catch(RchlValidatorException e){
//			e.getExceptionMessage().appendDetailText("CarController.myCars:"+"userId="+userId+",phone"+phone);
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.VALIDATION_ERROR.getValue(),
					e.getExceptionMessage().getSimpleText()+";"+e.getExceptionMessage().getDetailText());
			return answerMsg;
		}catch(BaseException e){
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.BUSINESS_ERROR.getValue(),
					e.getExceptionMessage().getSimpleText());
			return answerMsg;
		}catch (Exception e) {
			SystemUnKnown ex=new SystemUnKnown(e,
					ExceptionMessage.createExceptionMessage(SystemUnKnown.default_Name,
														"未知Exception", "orderId="+orderId));
			exceptionHandle.handle(ex);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.SYSTEM_ERROR);
			return answerMsg;
		}
	}
	
	
	/**
	  * payResultNotice(取消息订单)
	  * TODO(这里描述这个方法适用条件 – 可选)
	  * TODO(这里描述这个方法的执行流程 – 可选)
	  * TODO(这里描述这个方法的使用方法 – 可选)
	  * TODO(这里描述这个方法的注意事项 – 可选)
	  *
	  * @Title: payResultNotice
	  * @Description: TODO
	  * @param @param szOrderId
	  * @param @param payResult
	  * @param @param resultDescription
	  * @param @return    设定文件
	  * @return AnswerMsg    返回类型
	  * @throws
	  */
	@RequestMapping("/wx/payFee/cancelPayment")
	public AnswerMsg cancelPayment(String szOrderId) {
			
		try {
			/******验证字段********/
			RchlValidateBean vb = new RchlValidateBean();
			vb.getRequiredValidate().put("szOrderId", szOrderId);
			RchlValidateTools.validate(vb);
			/**************/
			
//			ParkDataResult parkDataResult = payFeeFacade.cancelPayment_rest_wx(szOrderId);
//			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createAnswerMsg(parkDataResult.getData());
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createAnswerMsg(null);
			return answerMsg;
		}catch(RchlValidatorException e){
//			e.getExceptionMessage().appendDetailText("CarController.myCars:"+"userId="+userId+",phone"+phone);
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.VALIDATION_ERROR.getValue(),
					e.getExceptionMessage().getSimpleText()+";"+e.getExceptionMessage().getDetailText());
			return answerMsg;
		}catch(BaseException e){
			exceptionHandle.handle(e);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.BUSINESS_ERROR.getValue(),
					e.getExceptionMessage().getName()+e.getExceptionMessage().getSimpleText());
			return answerMsg;
		}catch (Exception e) {
			SystemUnKnown ex=new SystemUnKnown(e,
					ExceptionMessage.createExceptionMessage(SystemUnKnown.default_Name,
														"未知Exception", "szOrderId="+szOrderId));
			exceptionHandle.handle(ex);
			AnswerMsg answerMsg = AnswerMsgFactoryImpl.createErrorAnserMsg(ResponseCodeEnum.SYSTEM_ERROR);
			return answerMsg;
		}
	}
}
